import { locationInit } from '../api/upload'

let dealy = 10000
let timer = null
 const locationFuc = () => {
    if (timer) clearInterval(timer)
    timer = setInterval(() => {
			const userInfo = uni.getStorageSync('USER_INFO')
			if (!userInfo) {
				clearInterval(timer)
			}
        uni.getLocation({
            geocode: true,
            async success(res) {
							const {latitude, longitude} = res
							const address = `${res.address.city}${res.address.district}${res.address.street}`
							if(userInfo) {
								await locationInit({lon:longitude, lat: latitude, address})
							}
							timer = null
            },
            async fail(e) {
							console.log('定位失败')
						}
        })
    }, dealy)
}
export default locationFuc